import request from '@/utils/request'
import { DELETE, GET, POST, PUT } from '@/constant'
import { order } from 'mockjs/src/mock/random/helper'

let API = {
  /**
   * 结算页面-生成订单 (根据购物车选中的商品来生成订单)
   * @return {*|AxiosPromise}
   */
  createOrder() {
    return request('/member/order/pre', GET)
  },
  /**
   * 结算页面-生成订单 - 根据订单选中的商品
   * @param orderId 订单Id
   */
  repurchaseOrder(orderId) {
    return request(`/member/order/repurchase/${orderId}`, GET)
  },
  /**
   * 添加收货地址
   * @param form  form表单对象
   */
  addAddress(form) {
    return request('/member/address', POST, form)
  },
  /**
   * 修改收货地址
   * @param form form表单对象
   */
  editAddress(form) {
    return request(`/member/address/${form.id}`, PUT, form)
  },
  /**
   * 结算页面 - 提交订单
   * @param order 订单数据对象
   */
  submitOrder(order) {
    return request('/member/order', POST, order)
  },
  /**
   * 获取订单详情
   * @param orderId 订单Id
   */
  getOrderDetail(orderId) {
    return request(`/member/order/${orderId}`, GET)
  },
  /**
   * 获取订单列表
   * @param page        页码
   * @param pageSize    页尺寸
   * @param orderState  订单状态 1为待付款、2为待发货、3为待收货、4为待评价、5为已完成、6为已取消, 0为或未传参数为全部
   */
  getOrderList(page = 1, pageSize = 10, orderState = 0) {
    return request('/member/order', GET, {
      page,
      pageSize,
      orderState
    })
  },
  /**
   * 取消订单
   * @param orderId       订单Id
   * @param cancelReason  取消理由
   */
  orderCancel(orderId, cancelReason) {
    return request(`/member/order/${orderId}/cancel`, PUT, { cancelReason })
  },
  /**
   * 删除订单
   * @param ids 订单id集合 | Array 数组类型
   */
  orderDelete(ids) {
    return request('/member/order', DELETE, { ids })
  },
  /**
   * 确认收货
   * @param orderId 订单id
   */
  orderConfirm(orderId) {
    return request(`/member/order/${orderId}/receipt`, PUT)
  },
  /**
   * 查询物流
   * @param orderId 订单Id
   */
  logisticsOrder(orderId) {
    return request(`/member/order/${orderId}/logistics`, GET)
  }
}

export default API
